home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_500 / wiconify / wiconify-source.lzh / Source / wTask.c < prev   
C/C++ Source or Header  |  1991-04-19  |  5KB  |  184 lines

  1. /*
  2.  *  WICONIFY    A utility that allows you to iconify any Intuition window
  3.  *              on any screen, and to open WB windows on any screen.
  4.  *
  5.  *  wTask.c     Handles creation of NewCLI processes.
  6.  *
  7.  *  Copyright 1990 by Davide P. Cervone, all rights reserved.
  8.  *  You may use this code, provided this copyright notice is kept intact.
  9.  */
  10.  
  11. #define INTUITION_PREFERENCES_H             /* don't need 'em */
  12. #include <intuition/intuitionbase.h>
  13. #include <libraries/dosextens.h>
  14. #include "wHandler.h"
  15. #include "wMenu.h"
  16.  
  17.  
  18. #define MYPROC   ((struct Process *)FindTask(NULL))
  19.  
  20. struct Segment            /* what a SegList looks like */
  21. {
  22.    ULONG Size;              /* size of this Segment */
  23.    BPTR  NextSeg;           /* BPTR to next SegList entry */
  24.    UWORD Nop;               /* NOP for longword alignment of JMP address */
  25.    UWORD Jmp;               /* JMP to code for child */
  26.    APTR  Address;           /* address of child's code */
  27. };
  28.  
  29. #define NOP     0x4E71      /* 68000 NOP instruction */
  30. #define JMP     0x4EF9      /* 68000 JMP instruction */
  31.  
  32.  
  33. static BPTR *NewCLISegPtr;
  34. static BPTR *EndIconifySegPtr;
  35. extern void GetNewCLI();
  36. extern void EndIconify();
  37.  
  38. /*
  39.  *  Dummy SegLists that call the GetNewCLI and EndIconify routines
  40.  */
  41.  
  42. static struct Segment GetNewCLISegment =
  43. {
  44.    sizeof(struct Segment),
  45.    NULL, NOP, JMP, (APTR)&GetNewCLI
  46. };
  47.  
  48. static struct Segment EndIconifySegment =
  49. {
  50.    sizeof(struct Segment),
  51.    NULL, NOP, JMP, (APTR)&EndIconify
  52. };
  53.  
  54.  
  55.  
  56. /*
  57.  *  IconError()
  58.  *
  59.  *  If there is an active wIconify window,
  60.  *    Set its title to the error message
  61.  *    Make sure the title bar is showing
  62.  */
  63.  
  64. void IconError(Error)
  65. char *Error;
  66. {
  67.    if (ActiveWindow)
  68.       SetWindowTitles(ActiveWindow,-ONE,Error),
  69.       ShowTitle(ActiveWindow->WScreen,TRUE);
  70. }
  71.  
  72.  
  73. /*
  74.  *  DoNewCLI()
  75.  *
  76.  *  Set the WB screen to the current one, so the CLI will open there
  77.  *  Calculate the BPTR to the SegList of the NewCLI routine
  78.  *  Create the process that executes the NewCLI command
  79.  *  If the process failed to open, give a message
  80.  */
  81.  
  82. void DoNewCLI(theScreen)
  83. WSCREEN *theScreen;
  84. {
  85.    APTR GetNewCLI;
  86.    extern APTR CreateProc();
  87.  
  88.    NewWBScreen(theScreen);
  89.    NewCLISegPtr = (BPTR *) (((ULONG)(&GetNewCLISegment.NextSeg)) >> 2);
  90.    GetNewCLI = CreateProc("GetNewCLI",5,NewCLISegPtr,StackSize);
  91.    if (GetNewCLI == NULL) IconError("Can't Create NewCLI Process");
  92. }
  93.  
  94.  
  95. /*
  96.  *  GetNewCLI()
  97.  *
  98.  *  This routine runs as a separate process so that wIconify will not
  99.  *  be held up during the Execute() command (it may put up a disk requester)
  100.  *  
  101.  *  If the screen is a LORES screen and there is a LoRes CLI command string
  102.  *    Use the LoRes command otherwise use the HiRes command
  103.  *  Change the window pointer of our process so that requesters will come
  104.  *    on the correct screen (the one where the NewCLI will appear)
  105.  *  Bring the screen where the NewCLI will open to front
  106.  *  Open NIL: as the output device
  107.  *  Use the DOS Execute() command to run the command with no input stream
  108.  *    and NIL: as the output stream
  109.  *  If we openned NIL:, close it
  110.  *  This process is now complete and should exit normally
  111.  */
  112.  
  113. static void GetNewCLI()
  114. {
  115.    char *NewCLICommand;
  116.    long Nil;
  117.    extern long Open();
  118.  
  119.    if (WBScreen && LoResCLICommand &&
  120.       (WBScreen->Screen->ViewPort.Modes & HIRES) == 0)
  121.          NewCLICommand = LoResCLICommand;
  122.         else
  123.          NewCLICommand = HiResCLICommand;
  124.  
  125.    Forbid(); 
  126.    if (WBScreen) MYPROC->pr_WindowPtr = (APTR)WBScreen->BackDrop;
  127.    if (WBScreen) ScreenToFront(WBScreen->Screen); else WBenchToFront();
  128.    Permit();
  129.    
  130.    Nil = Open("NIL:",MODE_NEWFILE);
  131.    Execute(NewCLICommand,NULL,Nil);
  132.    if (Nil) Close(Nil);
  133.  
  134.    Exit(0);
  135. }
  136.  
  137.  
  138. /*
  139.  *  DoEndIconify()
  140.  *
  141.  *  Get the BPTR to the SegList for the EndIconify routine
  142.  *  Create the process that will run the wIconify loader (to close wIconify)
  143.  *  If the process could not be created, give a message
  144.  */
  145.  
  146. void DoEndIconify()
  147. {
  148.    APTR EndIconify;
  149.    extern APTR CreateProc();
  150.  
  151.    EndIconifySegPtr = (BPTR *) (((ULONG)(&EndIconifySegment.NextSeg)) >> 2);
  152.    EndIconify = CreateProc("EndIconify",5,EndIconifySegPtr,4000L);
  153.    if (EndIconify == NULL) IconError("Can't Create EndIconify Process");
  154. }
  155.  
  156.  
  157. /*
  158.  *  EndIconify()
  159.  *
  160.  *  This routine runs as a separate process so that wIconify will not
  161.  *  be held up during the Execute() command (it may put up a disk requester)
  162.  *  
  163.  *  Make sure that system messages will appear on the right screen
  164.  *  Open NIL: for output
  165.  *  Try to run the wIconify program (since the handler does not include
  166.  *    any of the clean up code, we need to get the loader running again
  167.  *    in order to end wIconify)
  168.  *  Close the NIL: device
  169.  *  Our job is complete, so exit
  170.  */
  171.  
  172. static void EndIconify()
  173. {
  174.    long Nil;
  175.    extern long Open();
  176.  
  177.    Forbid(); 
  178.    if (WBScreen) MYPROC->pr_WindowPtr = (APTR)WBScreen->BackDrop;
  179.    Nil = Open("NIL:",MODE_NEWFILE);
  180.    Execute("C:RUN >NIL: <NIL: WICONIFY:wIconify <NIL: >NIL:",NULL,Nil);
  181.    if (Nil) Close(Nil);
  182.    Exit(0);
  183. }
  184.